package com.zyd.blog.personal.controller;

import com.zyd.blog.business.annotation.BussinessLog;
import com.zyd.blog.business.enums.ResponseStatus;
import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.personal.service.MerchantApplyDealService;
import com.zyd.blog.personal.vo.MerchantApplyInfoConditionVo;
import com.zyd.blog.personal.vo.ReviewResultVo;
import com.zyd.blog.util.ResultUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 商家合作审核
 * @author mfy
 */
@Controller
@RequestMapping("/merchantInfoReview")
public class MerchantInfoReviewController {

    @Resource
    private MerchantApplyDealService merchantApplyDealService;

    /**
     * 进入设计师用户界面
     * 访问路径 http://localhost:8085/merchantInfoReview
     * @return
     */
    @BussinessLog("设计师申请信息列表界面")
    @RequestMapping("")
    public ModelAndView front() {
        return ResultUtil.view("merchantInfo/applyList");
    }

    /**
     * 得到商家合作申请列表
     * 访问路径 http://localhost:8085/merchantInfoReview/list
     * @param merchantApplyInfoConditionVo   条件
     * @return  结果
     */
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(MerchantApplyInfoConditionVo merchantApplyInfoConditionVo) {
        List<Map<String,Object>> merchantInfoList = merchantApplyDealService.getMerchantApplyInfoList(merchantApplyInfoConditionVo);
        return ResultUtil.tablePage((long) merchantInfoList.size(),merchantInfoList);
    }


    /**
     * 得到设计师详细申请信息
     * 访问路径 http://localhost:8085/merchantInfoReview/merchantDetailInfo
     * @return  页面
     */
    @RequestMapping("/merchantDetailInfo/{id}")
    @ResponseBody
    public ResponseVO merchantDetailInfo(@PathVariable("id") Long id) {
        Map<String,Object> result = merchantApplyDealService.getDetailMerchantApplyInfo(id);
        System.out.println(result);
        return ResultUtil.success(null, result);
    }

    /**
     * 删除设计师信息
     * 访问路径 http://localhost:8085/merchantInfoReview/del
     * @param id    申请id
     * @return  页面
     */
    @RequestMapping("/del")
    @ResponseBody
    public ResponseVO del(Long id){
        try {
            merchantApplyDealService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("删除失败！");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }


    /**
     * 审核设计师申请
     * 访问路径 http://localhost:8085/merchantInfoReview/review
     * @param reviewResultVo    审核结果
     * @return  操作结果
     */
    @RequestMapping("/review")
    @ResponseBody
    public ResponseVO review(ReviewResultVo reviewResultVo){
        System.out.println(reviewResultVo);
        if(ReviewResultVo.resultOfFaild.equals(reviewResultVo.getResult())){
            return ResultUtil.success(ResponseStatus.SUCCESS);
        }
        try {
            merchantApplyDealService.review(reviewResultVo);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("删除失败！");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }


}
